import time
from dataclasses import replace

from selenium import webdriver
from selenium.webdriver.common.by import By

# 设置浏览器驱动
driver=webdriver.Edge()
# 启动浏览器网址
driver.get('http://10.59.9.12:7001/')
driver.maximize_window()
time.sleep(2)
# 点击登录
driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
time.sleep(2)
# 断言登录页面
dy1 = driver.find_element(By.CLASS_NAME,'reg-new').text
assert '会员登录' == dy1
print(dy1)
# 输入用户名
driver.find_element(By.XPATH,'//input[@type="text" and @name="username"]').send_keys('123455556666')
time.sleep(2)
# 输入密码
driver.find_element(By.XPATH,'//input[@type="password" or @name="password"]').send_keys('123456')
time.sleep(10)
# 点击登录
driver.find_element(By.XPATH,'//a[@class="finish-btn"]').click()
time.sleep(5)
# 登录成功断言
dy2 = driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[1]').text
print(dy2)
# 点击首页
driver.find_element(By.CSS_SELECTOR,'.nav-wrap > ul:nth-child(1) > li:nth-child(1) > a:nth-child(1)').click()
time.sleep(2)
# 输入框输入搜索内容
driver.find_element(By.CLASS_NAME,'search-input').send_keys('非洲之心')
time.sleep(2)
# 点击搜索
driver.find_element(By.XPATH,'//*[@id="searchForm"]/div[2]/input').click()
time.sleep(2)
# 点击商品
driver.find_element(By.CLASS_NAME,'lazy').click()
time.sleep(2)
# 点击立即购买
driver.find_element(By.ID,'buy-cart').click()
time.sleep(2)
# 断言进入订单页面
dy3 = driver.find_element(By.XPATH,'/html/body/div[4]/div[1]/a[2]').text
print(dy3)
# 点击收货地址
driver.find_element(By.ID,'address-831').click()
time.sleep(2)
# 点击支付方式
driver.find_element(By.NAME,'payment').click()
time.sleep(2)
# 下滑页面
driver.execute_script('window.scrollTo(0,2000)')
time.sleep(2)
# 点击下一步
driver.find_element(By.CLASS_NAME,'ask-btn').click()
time.sleep(2)
# 订单完成断言
dy4 = driver.find_element(By.XPATH,'/html/body/div[4]/div[1]/a[2]').text
print(dy4)




